package com.sto.stoapp.activity.administrator.system;

import android.content.res.AssetManager;
import android.os.Bundle;
import android.widget.TextView;

import com.sto.stoapp.activity.R;
import com.sto.stoapp.broadcast.HomeBroadAction;
import com.sto.stoapp.log.ExceptionLog;
import com.sto.stoapp.widget.StoHomeActivity;

import java.io.IOException;
import java.io.InputStream;

public class SystemUserDeclareActivity extends StoHomeActivity {

	private TextView declareText;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.system_declare);
		String broadType = getIntent().getStringExtra(
				HomeBroadAction.BROAD_TYPE);
		if (broadType != null && !broadType.equals("")) {
			this.setTitleBottom(R.string.direction_for_use, broadType);
		} else {
			this.setTitleBottom(R.string.direction_for_use,
					HomeBroadAction.ADMINISTRATOR_BROAD);
		}
		initText();
	}

	private void initText() {
		declareText = (TextView) findViewById(R.id.declare_text);
		AssetManager assetManager = getAssets();
		InputStream is = null;
		try {
			is = assetManager.open("declare.txt");
		} catch (Exception e) {
			e.printStackTrace();
			ExceptionLog.writeLog("initText", e.getMessage());
		}
		String conHelp = readTextFile(is);
		declareText.setText(conHelp);
	}

	private String readTextFile(InputStream inputStream) {

		byte buf[] = new byte[16 * 1024];

		int len;
		String s = null;
		try {
			len = inputStream.read(buf);
			s = new String(buf, 0, len, "UTF-8");
			s = s.replace("\r\n", "\n");
		} catch (IOException e) {
			ExceptionLog.writeLog("readTextFile", e.getMessage());
		}
		return s;
	}
	

}
